package entity

import (
	"time"
	"xr-game-server/core/constants/db"
	"xr-game-server/core/migrate"
	"xr-game-server/core/snowflake"
	"xr-game-server/core/syndb"
)

const (
	TbRoleSysMail db.TbName = "role_sys_mails"
)

const (
	RoleSysMailRoleId db.TbCol = "role_id"
	RoleSysMailMailId db.TbCol = "mail_id"
)

type RoleSysMail struct {
	migrate.MoreModel
	RoleId uint64 `gorm:"comment:角色id"`
	MailId uint64 `gorm:"comment:邮件id"`
}

func initRoleSysMail() {
	migrate.AutoMigrate(&RoleSysMail{})

	syndb.RegLazyWithSmall(TbRoleSysMail, RoleSysMailRoleId)
	syndb.RegLazyWithSmall(TbRoleSysMail, RoleSysMailMailId)
	syndb.RegLazyWithSmall(TbRoleSysMail, db.CreatedAtName)
	syndb.RegLazyWithSmall(TbRoleSysMail, db.UpdatedAtName)
	syndb.RegLazyWithSmall(TbRoleSysMail, db.IsDeletedName)
	syndb.RegLazyWithSmall(TbRoleSysMail, db.DeletedAtName)
}
func NewRoleSysMail(roleId uint64, mailId uint64) *RoleSysMail {
	ret := &RoleSysMail{}
	ret.ID = snowflake.GetId()
	ret.SetMailId(mailId)
	ret.SetRoleId(roleId)
	ret.SetCreateAt(time.Now())
	ret.SetIsDeleted(true)
	ret.SetUpdateAt(time.Now())
	return ret
}

// 帮我生成setter方法
func (receiver *RoleSysMail) SetRoleId(roleId uint64) {
	receiver.RoleId = roleId
	syndb.AddDataToLazyChan(TbRoleSysMail, RoleSysMailRoleId, &syndb.ColData{
		IdVal:  receiver.ID,
		ColVal: roleId,
	})
}
func (receiver *RoleSysMail) SetMailId(mailId uint64) {
	receiver.MailId = mailId
	syndb.AddDataToLazyChan(TbRoleSysMail, RoleSysMailMailId, &syndb.ColData{
		IdVal:  receiver.ID,
		ColVal: mailId,
	})
}
func (receiver *RoleSysMail) SetCreateAt(val time.Time) {
	receiver.CreatedAt = val
	syndb.AddDataToLazyChan(TbRoleSysMail, db.CreatedAtName, &syndb.ColData{
		IdVal:  receiver.ID,
		ColVal: val,
	})
}
func (receiver *RoleSysMail) SetUpdateAt(val time.Time) {
	receiver.UpdatedAt = val
	syndb.AddDataToLazyChan(TbRoleSysMail, db.UpdatedAtName, &syndb.ColData{
		IdVal:  receiver.ID,
		ColVal: val,
	})
}
func (receiver *RoleSysMail) SetIsDeleted(val bool) {
	receiver.IsDeleted = val
	receiver.SetDeletedAt(time.Now())
	syndb.AddDataToLazyChan(TbRoleSysMail, db.IsDeletedName, &syndb.ColData{
		IdVal:  receiver.ID,
		ColVal: val,
	})
}
func (receiver *RoleSysMail) SetDeletedAt(val time.Time) {
	receiver.DeletedAt = val
	syndb.AddDataToLazyChan(TbRoleSysMail, db.DeletedAtName, &syndb.ColData{
		IdVal:  receiver.ID,
		ColVal: val,
	})
}
